//
//  FinancialRootNewsViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/10/22.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit
import XLPagerTabStrip

@objc protocol FinancialRootNewsDelegate {
    @objc optional func changeScrollHeight(height:CGFloat) //改变滑动高度
    @objc optional func updateTitle() //刷新标题
}

class FinancialRootNewsViewController: InformationPageViewController {
    
    weak var financialDelegate : FinancialRootNewsDelegate?

    override func viewDidLoad() {
        super.viewDidLoad()

        
    }
    
    //MARK: 更多标签
    override func moreLabel() {
        
        let dataArray = [todayHeadlines,featuredFavourites,bankFinancing,peerBanking,campusLoan,wealthStory,financialComics,financialEvaluation,exposureTable,wealthStrategy,rvProducts,exclusive,featuredStories,financialLife,internetFinance,fund,insurance_title]
        
        let moreLabelVC = MoreLabelViewController.init(dataArray: dataArray)
        moreLabelVC.labelBlock = {(index) in
            self.moveToViewController(at: index.row, animated: true) //切换至选择标签
        }
        
        self.present(moreLabelVC, animated: false, completion: nil)
    }
    
    //MARK: 滑动的子控制
    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        
        let titleArray = [todayHeadlines,featuredFavourites,bankFinancing,peerBanking,campusLoan,wealthStory,financialComics,financialEvaluation,exposureTable,wealthStrategy,rvProducts,exclusive,featuredStories,financialLife,internetFinance,fund,insurance_title]
        let urlArray = ["52","0","53","54","55","56","57","58","59","60","105","61","62","104","106","107","108"]
        
        var viewControllers = [UIViewController]()
        
        for i in 0..<titleArray.count {
            let financialNewsVC = FinancialNewsViewController.init(urlString: urlArray[i])
            financialNewsVC.delegate = self
            financialNewsVC.itemInfo.title = titleArray[i]
            viewControllers.append(financialNewsVC)
        }
        
        return viewControllers
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    

}

extension FinancialRootNewsViewController : FinancialNewsDelegate {
    
    //MARK: 更新标题
    func updateTitle() {
        self.financialDelegate?.updateTitle!()
    }
    
    //MARK: 改变坐标
    func changeScrollHeight(height: CGFloat) {
        self.financialDelegate?.changeScrollHeight!(height: height)
    }
}
